package com.geek.jdbc.work2;

import java.sql.Date;
import java.util.Scanner;

/*
 *@Date 2025/11/17
 *@Author wangpeng
 *@Description TODO
 */
public class CustomersTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        CustomersDao cusDao = new CustomersDao();
        Customers cus = null;

        while (true) {
            System.out.println("===========请选择操作键===========");
            System.out.println("1.添加客户");
            System.out.println("2.修改指定客户姓名");
            System.out.println("3.查询所有客户信息");
            System.out.println("4.根据编号查询");
            System.out.println("5.根据姓名查询");
            System.out.println("0.退出");
            System.out.println("请输入选择");
            switch (sc.nextInt()){
                case 1:
                    System.out.print("请输入客户编号");
                    String id1 = sc.next();
                    //System.out.println("");
                    System.out.print("请输入客户姓名");
                    String name1 = sc.next();
                    System.out.print("请输入客户邮箱");
                    String email1 = sc.next();
                    System.out.print("请输入客户生日");
                    String birthday1 = sc.next();
                    cusDao.insert(new Customers(id1,name1,email1, Date.valueOf(birthday1)));
                    System.out.println("添加成功");
                    break;
                case 2:
                    System.out.println("请输入要修改的客户编号");
                    String id2 = sc.next();
                    System.out.println("请输入修改后的姓名");
                    String name2 = sc.next();
                    cusDao.updateNameById(name2, id2);
                    System.out.println("修改成功");
                    break;
                case 3:
                    System.out.println("编号\t姓名\t\t\t邮箱\t\t\t\t生日");
                    for (Customers cus3 : cusDao.selectAll()) {
                        System.out.println(cus3.getId()+"\t"+cus3.getName()+"\t\t"+cus3.getEmail()+"\t\t"+cus3.getBirthday());
                    }
                    break;
                case 4:
                    System.out.println("请输入要查询的客户编号");
                    String id4 = sc.next();
                    System.out.println("编号\t姓名\t\t\t邮箱\t\t\t\t生日");
                    cus = cusDao.selectById(id4);
                    if (cus != null) {
                        System.out.println(cus.getId()+"\t"+cus.getName()+"\t"+cus.getEmail()+"\t"+cus.getBirthday());
                    } else {
                        System.out.println("未找到该编号的客户信息");
                    }
                    break;
                case 5:
                     System.out.println("请输入要查询的客户姓名");
                    String name5 = sc.next();
                    System.out.println("编号\t姓名\t\t\t邮箱\t\t\t\t生日");
                    cus = cusDao.selectByName(name5);
                    if (cus != null) {
                        System.out.println(cus.getId()+"\t"+cus.getName()+"\t"+cus.getEmail()+"\t"+cus.getBirthday());
                    } else {
                        System.out.println("未找到该姓名的客户信息");
                    }
                    break;
                case 0:
                    System.exit(0);
                    break;
                default:
                    System.out.println("输入有误，请重新输入");
            }
        }


    }
}
